package com.igfd.tanmao.controller;

import com.igfd.tanmao.pojo.ExcelData;
import com.igfd.tanmao.service.ItemsService;
import com.igfd.tanmao.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class TanmaoController {

    @Autowired
    private ItemsService itemsService;

    @GetMapping(value = "excelInventory")
    public void exportInventoryTable(HttpServletResponse response) throws Exception {
        ExcelData data = new ExcelData();
        data.setName("用户信息数据");
        //添加表头
        List<String> titles = new ArrayList();
        //for(String title: excelInfo.getNames())
        titles.add("图片");
        titles.add("numIid");
        titles.add("skuId");
        titles.add("原厂货号");
        titles.add("SPU");
        titles.add("标题");
        titles.add("颜色");
        titles.add("尺寸");
        titles.add("价格");
        titles.add("数量");
        data.setTitles(titles);

        //添加列
        data.setRows(itemsService.getTanmaoInventoryInfo("61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057"));

        SimpleDateFormat fdate=new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName="天猫库存_" + fdate.format(new Date())+".xls";
        ExcelUtils.exportExcel(response, fileName, data);
    }

}
